package logic

import (
	"context"
	"shop_srv/models"

	"shop_srv/internal/svc"
	"shop_srv/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopListLogic {
	return &ShopListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopListLogic) ShopList(in *shop.ShopListRequest) (*shop.ShopListResponse, error) {
	// todo: add your logic here and delete this line

	var s models.Shop
	var listShop []*shop.ShopList

	find, err := s.ShopList(in.SortWord, in.KeyWord, in.PriceWord)
	if err != nil {
		return nil, err
	}

	for _, h := range find {
		list := shop.ShopList{
			Title:      h.Title,
			Score:      h.Score,
			Sales:      h.Sales,
			Distance:   h.Distance,
			Types:      h.Types,
			Price:      h.BePrice,
			BePrice:    h.Price,
			Promotions: h.Promotions,
		}
		listShop = append(listShop, &list)
	}
	return &shop.ShopListResponse{}, nil
}
